package ma.ensao.evalmetrics.controller.metrics;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import ma.ensao.evalmetrics.model.I;
import ma.ensao.evalmetrics.model.ResultClasse;

import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaSource;

public class ClassMetrics {
	
	ResultClasse currentClass = new ResultClasse();
	DITManager ditM;
	IManager im;
	I instab;
	int dit;
	
	public ClassMetrics(){
		ditM = new DITManager();
		im = new IManager();
	}
	
	public List<ResultClasse> read(File file) {
		// TODO Auto-generated method stub
		List<ResultClasse> liste = new ArrayList<ResultClasse>();
		JavaDocBuilder builder = new JavaDocBuilder();
		try {
			builder.addSource(file);
			instab = im.read(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JavaSource src = builder.getSources()[0];
		JavaClass[] classes = src.getClasses();
		for(int j=0;j<classes.length;j++){
		JavaClass jc = classes[j];
		currentClass.setNom(jc.getMethods().length);
		currentClass.setClasseName(jc.getFullyQualifiedName());
		currentClass.setCa(instab.getCp());
		currentClass.setCe(instab.getCe());
		currentClass.setInstab(instab.getIn());
		dit= ditM.read(file, jc,builder,src);

		currentClass.setDit(dit);

		liste.add(currentClass);
		}
		return liste;

	}
	public static void main(String[] args) throws IOException {
		ClassMetrics cm =new ClassMetrics();
		File file = new File("C:/Users/sam/Desktop/RatRoidClient/src/com/hicham/ratroid/A.java");
		cm.read(file);
	}

}
